import Mock from 'mockjs'

const Random = Mock.Random

/**
 * 生成用户信息数据
 */
const generateUserInfo = () => {
  const departmentNames = ['内科', '外科', '儿科', '妇产科', '急诊科', '检验科', '放射科', '药剂科', '行政部', '信息部']
  const department = Random.pick(departmentNames)
  const gender = Random.pick(['male', 'female'])
  
  return {
    code: 200,
    message: 'success',
    data: {
      id: Random.string('number', 6),
      name: Random.cname(),
      gender,
      avatar: gender === 'male' 
        ? `https://randomuser.me/api/portraits/men/${Random.integer(1, 99)}.jpg`
        : `https://randomuser.me/api/portraits/women/${Random.integer(1, 99)}.jpg`,
      department,
      position: Random.pick(['医师', '主治医师', '主任医师', '护士', '护士长', '技师', '管理员']),
      phone: '1' + Random.string('number', 10),
      email: Random.email(),
      birthDate: Random.date('yyyy-MM-dd'),
      joinDate: Random.date('yyyy-MM-dd'),
      address: Random.province() + Random.city() + Random.county(),
      intro: Random.cparagraph(1, 3)
    }
  }
}

/**
 * 生成用户通知数据
 */
const generateUserNotifications = () => {
  const count = Random.integer(0, 10)
  const list = []
  
  for (let i = 0; i < count; i++) {
    list.push({
      id: Random.guid(),
      title: Random.csentence(5, 15),
      content: Random.cparagraph(1, 3),
      type: Random.pick(['system', 'task', 'message']),
      status: Random.pick(['read', 'unread']),
      date: Random.date('yyyy-MM-dd HH:mm:ss')
    })
  }
  
  return {
    code: 200,
    message: 'success',
    data: {
      list,
      unreadCount: list.filter(item => item.status === 'unread').length
    }
  }
}

/**
 * 设置用户资料模块Mock
 */
export function setupProfileMock() {
  // 获取用户信息
  Mock.mock('/api/profile/user', 'get', generateUserInfo)
  
  // 更新用户资料
  Mock.mock('/api/profile/update', 'post', () => {
    return {
      code: 200,
      message: 'success',
      data: {
        success: true
      }
    }
  })
  
  // 修改密码
  Mock.mock('/api/profile/password', 'post', () => {
    return {
      code: 200,
      message: 'success',
      data: {
        success: true
      }
    }
  })
  
  // 获取用户通知
  Mock.mock('/api/profile/notifications', 'get', generateUserNotifications)
} 